********************************************************************************
*********						 FIG 2 - WILLINGNESS-TO-PAY PER 
*********			HOUR AND DEMAND FOR TRIPS IN THE EXPRESSLANES      *********
********************************************************************************
use .\data\clean\I10W_laneuse_dataset_15nov14_wcensus, clear
drop if holiday==1
drop if dow==0 | dow==6
keep if acct_type=="PRIVATE"
drop TTdiff_ELSpeed
g TTdiff_ELSpeed= (dist/MLspeed)-(dist/ELspeed)
sort acct_no
keep if inlist(hour,5,6,7,8) /*period=="AM Peak"*/
gen WTP=charged_toll/(TTdiff_ELSpeed)
gen temp1=WTP<0
gen Price_per_mile=charged_toll/dist
g miles=cond(dist<2,"0-2", ///
	cond(dist<5, "2-5", ///
	cond(dist<7, "5-7", "7-10.5")))

*create frequency
sort acct_no
keep if WTP>0&WTP~=.
replace TTdiff_ELSpeed=TTdiff_ELSpeed*60


sort acct_no
g count=1
egen freqpermo=sum(count), by(acct_no month)
sort acct_no entry_time
egen appearance=seq(), by(acct_no)


*lpoly WTP TTdiff_ELSpeed if TTdiff_ELSpeed>1.5,bwidth(.05) nograph gen( WTP_x WTP_s)

*** PANEL A
*kdensity TTdiff_ELSpeed , bwidth(.05) nograph gen(TTdiff_x TTdif_s)
		twoway (lpoly WTP TTdiff_ELSpeed if TTdiff_ELSpeed>1.5,bwidth(.05) lc(black)), ///
		 ytitle("Willingness-to-Pay per Hour" "(in dollars)") ///
		 xtitle("{&Delta}Travel Time (in minutes)") xlabel(0(5)30)  ylabel(0(20)120)  scale(1.5) /// 
	   legend(off) plotregion(style(none))
	graph export .\results\maintablesfigs\figs\fig2_panela.png, replace

*** PANEL B
twoway (kdensity TTdiff_ELSpeed , bwidth(.05) lc(black)) , ytitle("Smoothed Density") ///
	xtitle("{&Delta}Travel Time (in minutes)") xlabel(0(5)30) xmtick(1(1)28)  scale(1.5) ///
	ylabel(,format(%03.2f)) ///
	   legend(off) plotregion(style(none))
graph export .\results\maintablesfigs\figs\fig2_panelb.png, replace


*** PANEL C
twoway (lpoly WTP TTdiff_ELSpeed if TTdiff_ELSpeed>1.5 & freqpermo<4,bwidth(.05) lc(black)), ///
		 ytitle("Willingness-to-Pay per Hour" "(in dollars)") ///
		 xtitle("{&Delta}Travel Time (in minutes)") xlabel(0(10)30)  ylabel(0(20)120) /// 
	   legend(off) plotregion(style(none)) name(WTP_3, replace) ysc(r(0 125)) scale(1.5)
graph export .\results\maintablesfigs\figs\fig2_panelc.png, replace


twoway (lpoly WTP TTdiff_ELSpeed if TTdiff_ELSpeed>1.5 & freqpermo>3 & freqpermo<11,bwidth(.05) lc(black)), ///
		 ytitle("Willingness-to-Pay per Hour" "(in dollars)") ///
		 xtitle("{&Delta}Travel Time (in minutes)") xlabel(0(10)30)  ylabel(0(20)120)  /// 
	   legend(off) plotregion(style(none)) name(WTP_4_10, replace)  ysc(r(0 125)) scale(1.5)
graph export .\results\maintablesfigs\figs\fig2_paneld.png, replace


putexcel set ".\results\maintablesfigs\maintextFigsTabs.xlsx", sheet("Figure 1") modify
putexcel A1 = picture(.\results\maintablesfigs\figs\fig2_panela.png)
putexcel AH1 = picture(.\results\maintablesfigs\figs\fig2_panelb.png)
putexcel A30 = picture(.\results\maintablesfigs\figs\fig2_panelc.png)
putexcel AH30 = picture(.\results\maintablesfigs\figs\fig2_paneld.png)

